var Email = {
	openCustomerDialog: function(baseUrl){
	    
	    var url = baseUrl + "/customer/customer/searchcustomer/from/email";
	    Common.showDialog({
        url : url ,
        height : 450 ,
        width : 930 ,
        dataDiv : "searchDialog"
        });
     },

     searchCustomer : function(emails){
    	var emailList = $('#send_to_area').val();
     	if(emails){
     		 
     		 var emailArr = emailList.split(",");
              $(emails).each(function(n,obj){
                  if(!Email.in_array(obj.email,emailArr)){
                	  emailArr.push(obj.email);
                	  if(emailList){
                		  emailList += ','+obj.email;
                	  } else {
                		  emailList = obj.email;
                	  }
                  }
               
              });
     		
     	} 
     	$("#send_to_area").val(emailList);
         Common.closeDialog("searchDialog");
     },
     
     
     in_array : function(stringToSearch, arrayToSearch) {
          for (var s = 0; s <arrayToSearch.length; s++) {
                thisEntry = arrayToSearch[s].toString();
                if (thisEntry == stringToSearch) {
                     return true;
                }
          }
           return false;
      },
     
     sendEmail : function(baseUrl){
    	  var result = true;
    	  var certfs = $("input[name='certf']");
    	  var ranks = $("input[name='rank']");
    	  var certfStr = '';
    	  var rankStr = '';
    	  $(certfs).each(function(n,obj){
    		  if($(obj).attr("checked") == true){
    			  if(certfStr){
    				  certfStr += ','+$(obj).val();
    			  } else {
    				  certfStr = $(obj).val();
    			  }
    		  }
    	  });
    	  $(ranks).each(function(n,obj){
    		  if($(obj).attr("checked") == true){
    			  if(rankStr){
    				  rankStr += ','+$(obj).val();
    			  } else {
    				  rankStr = $(obj).val();
    			  }
    		  }
    	  });
    	  $('#receiverError').empty();
    	  var emailStr = $('#send_to_area').val();
    	  if(!certfStr && !rankStr && !emailStr){
    		  var receiverEmptyInfo = $('#receiverEmpty').val();
    		  $('#receiverError').text(receiverEmptyInfo);
    		  result = false;
    	  }
    	  
    	  if(!Email.validateEmpty('subject')){
    		  result = false;
    	  }
    	  if(!Email.validateEmpty('content')){
    		  result = false;
    	  }
    	  if(!result){
    		  return;
    	  }
    	 var subject = $('#subject').val();
    	 var content = $('#content').val();
    	 var data = {
    			       "certfStr" : certfStr, 
    			       "rankStr" : rankStr, 
    			       "emailStr" : emailStr,
    			       "subject" : subject,
    			       "content" : content
    	            };
    	 
    	  $.ajax({
              type: 'post', 
              url: baseUrl+'/systemlog/email/send', 
              data: data, 
              async: false,  //false is synchronization , true is asynchronism
              dataType : 'json',
              success: function(response){ 
    		       jAlert("邮件发送成功");
    		      // window.location = baseUrl+'/systemlog/email';
    	      }
               
           });
    	 
      },
      
      validateEmpty : function(label){
    	  var result = true;
	      var value = $.trim($("#"+label).val());
          ValidationUtil.clearErrorMsg(label);
          if(ValidationUtil.isBlank(value)){
              ValidationUtil.showErrorMsg(label, label+"Empty");
              result = false;
          }
          
          return result;
      }
      
      


}